<template>
  <div>
    用户名：<input type="text" v-model="usrename">
    密码：<input type="password" v-model="password">
    <button @click="deng">登录</button>
  </div>
</template>

<script>
  import axios from 'axios'
    export default {
        name: "Login",
      data(){
          return{
            usrename:'',
            password:''
          }
      },
      methods:{
          deng(){
            axios({
              url:'http://127.0.0.1:8000/login/',
              method:'post',
              data:{
                usrename: this.usrename,
                password: this.password
              }
            }).then(res=>{
              console.log(res);
              if (res.data.code==200){
                localStorage.setItem('uid',res.data.data);
                this.$router.push({'name':'Books'})
              }else {
                alert('账号或密码错误')
              }
            })
          }
      }
    }
</script>

<style scoped>

</style>
